<?php
require_once('lanceur_spip.php'); // SPIP autoload

class TestFunctions_pdk_common extends SpipTest {    
	/**
     *  Some operations before all tests
     */
	function __construct() {
	   include_spip('functions/pdk_common');
    }
    /**
     *  Run before each test
     */
    function setUp() {
        
    }
    
    /**
     *  Run after each test
     */
    function tearDown() {
        
    }
    
    /**
     *  Some operations after all tests
     */
	function __destruct() {
        
    }
    
    function Test_pdk_load_class() {        
        $this->assertTrue(function_exists('pdk_load_class'), "Function pdk_load_class doesn't exist or hasn't been loaded automatically!");
        
        // Simple test
        $instance = pdk_load_class('pdk_model', 'classes');
        $this->assertTrue(class_exists('pdk_Model'));
        $this->assertEqual('pdk_Model',get_class($instance));
        unset($instance);
        
        // Optional '/' in the end
        $instance = pdk_load_class('PdkRechercher', 'classes/');
        $this->assertTrue(class_exists('PdkRechercher'));
        $this->assertEqual('PdkRechercher',get_class($instance));
        unset($instance);
        
        // Find files even with 'class.' prefix in filename
        $instance = pdk_load_class('phpmailer', 'classes/phpmailer');
        $this->assertTrue(class_exists('PHPMailer'));
        $this->assertEqual('PHPMailer',get_class($instance));
        unset($instance);
        
        // If class extension exist, it must be loaded alongside original class
        // Extension class instance must be returned  
        $instance = pdk_load_class('PdkTestTable', 'classes/simpletest');
        $this->assertTrue(class_exists('PdkTestTable'));
        $this->assertTrue(class_exists('MY_PdkTestTable'));
        $this->assertEqual('MY_PdkTestTable',get_class($instance));
        unset($instance);
        
        // Check if loaded class is singleton:
        $instance = pdk_load_class('pdk_validation', 'classes/');
        $instance->test = 'TEST';
        $instance2 = pdk_load_class('pdk_validation', 'classes/');        
        $this->assertEqual('TEST', $instance2->test);
        unset($instance);        
        unset($instance2);
    }
}